﻿﻿<!--********************* Part1:Jsp Head *********************-->
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/framework/head.jsp"%>
<%@page import="framework.core.StringUtil"%>
<%@page import="framework.core.DBResult"%>
<%@page import="framework.core.DBEngine"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="com.hitrust.gs.lib.*"%>
<!--********************* Part2:Java Code *********************-->
<%
User user=loginInfo.getUser();
boolean isTel=user.getTel().equals("1");
    WarehouseProductViewSearchEvent event = (WarehouseProductViewSearchEvent)context.getSessionValue("WarehouseProductViewSearchEvent");
    ObjectList list = WarehouseProductView.fetch().search(con,event);
    String sql = "select sum(Product_Money) from WAREHOUSE_PRODUCT_VIEW ";
    DBResult dbrs = DBEngine.doSelect(con, sql, event.toConditions());
    ResultSet rs = dbrs.getRs();
    String allMoney = "0";
    if(rs.next()){
        allMoney = dbrs.getRs().getString(1)==null ? "0" : dbrs.getRs().getString(1);    
    }
    dbrs.clear();   
    ObjectList warehouseList = (ObjectList)context.getSessionValue("WarehouseListDetail");
    
    String uiListDataTR_My1 = "<tr align='center' height=\"24\"  bgcolor=\"#FFFF37\"   onmouseover='this.style.backgroundColor=\"#D0DBE6\"' onmouseout='this.style.backgroundColor=\"#FFFF37\"'";
    String uiListDataTR_My2 = "<tr align='center' height=\"24\"  bgcolor=\"#FFA042\"   onmouseover='this.style.backgroundColor=\"#D0DBE6\"' onmouseout='this.style.backgroundColor=\"#FFA042\"'";     
    String uiListDataTR_My3 = "<tr align='center' height=\"24\"  bgcolor=\"#FF5809\"   onmouseover='this.style.backgroundColor=\"#D0DBE6\"' onmouseout='this.style.backgroundColor=\"#FF5809\"'";
    String uiListDataTR_My4 = "<tr align='center' height=\"24\"  bgcolor=\"#800080\"   onmouseover='this.style.backgroundColor=\"#D0DBE6\"' onmouseout='this.style.backgroundColor=\"#800080\"'";
    String []uiListDataTR_My = new String[]{uiListDataTR_My1, uiListDataTR_My2, uiListDataTR_My3,uiListDataTR_My4}; 
%>

<!--********************* Part3:JavaScript Code ***************-->
<!--start 客户端脚本区域-->
<%@page import="system.base.WarehouseProductView"%>
<%@page import="system.base.WarehouseStaff"%>
<%@page import="system.base.ProductStorage"%>
<%@page import="system.base.Position"%>
<script language=javascript>

var list_code = "listProductStorage";

function doSearch()
{
    var warehouseCodes = $.jstree._reference("#warehouseLevel").get_checked();
    var warehouseList = new Array();
     var i = 0;
     $.each(warehouseCodes, function() {
	           warehouseList[i] =($(this).attr("id"));
	           i++;
	 });

    SetValue("WarehouseCodes",warehouseList); 
    SetValue("s_ProductCode",GetValue("i_ProductCode")); //产品编码

    SetValue("s_ProductName",GetValue("i_ProductName")); //产品名称
    
    SetValue("s_KeyWord",GetValue("i_KeyWord")); //关键字

    SetValue("s_ProviderName",GetValue("i_ProviderName")); //供应商名称

    SetValue("s_IsIncludeZeroStorage",GetValue("i_IsIncludeZeroStorage")); //包含零库存

    SetValue("s_IsNormal",GetValue("i_IsNormal")); //是否正式产品
    
    SetValue("s_DullStorage",GetValue("i_DullStorage")); //呆滞库存
    
    SetValue("s_IsBuy",GetValue("i_IsBuy")); //
    
    SetValue("s_BalanceMode",GetValue("i_BalanceMode")); //结算模式
    
    SetValue("s_StartLastUpdate",GetValue("i_StartLastUpdate")); //最后修改开始时间

    SetValue("s_EndLastUpdate",GetValue("i_EndLastUpdate")); //最后修改结束时间
    
    SetValue("s_KeeperStaffId",GetValue("i_KeeperStaffId")); //管理员id
    SetValue("s_PositionCode",GetValue("i_PositionCode")); //货位CODE
    
    SetValue("s_OrderField",GetValue("i_OrderField")); //排序
    SetValue("s_OrderDesc",getCheckBoxValues("i_OrderDesc")); //升降序
    doCommonSearch();
}

function doExport()
{
    SetAction("exportProductStorage");
    frm.submit();
}
function createOrder(){
    var checks=document.getElementsByName("ids");
    var count=0;
    var array=new Array();
    for(var a=0;a<checks.length;a++){
        if(checks[a].checked){
            array[count]=checks[a].value;
            count++;
        }
    }
    if(count==0){
        alert("请选择生成订单产品！");
        return false;
    }
    if(count>10){
        alert("生成订单产品不能超过10个!");
        return false;
    }
    for(var i=0;i<array.length;i++){
        var val=array[i].split("@@")[1];
        for(var j=i+1;j<array.length;j++){
            var val2=array[j].split("@@")[1];
            if(val!=val2){
                alert("请选择同一仓库生成订单");
                return false;
            }
        }
    }
    
    var url = "<%=response.encodeURL(request.getContextPath()+"/A100110.do")%>?val="+array;
    window.open(url,null," center=Yes, help=No, resizable=Yes, status=Yes, width=900px, height=600px, scrollbars=yes");
}
/*function bizViewProductStorage(id)
{
    viewWin("<%=Config.getSrv()%>?action_code=viewProductStorage&Id="+id);
}

function doDelete()
{
    if(!hasChooseRadio("ids"))
    {
        bizMessage("删除","库存表");
        return false;
    }
    if(!bizConfirm("删除","库存表")) return false;
    SetAction("deleteProductStorage");
    frm.submit();
}

function doToAdd()
{
    SetAction("toAddProductStorage");
    frm.submit();
}

function doToUpdate()
{
    if(!checkOne("ids")) 
    {
        bizMessage("修改","库存表");
        return false;
    }
    SetValue("Id",getCheckBoxValue("ids"));
    SetAction("toUpdateProductStorage");
    frm.submit();
}
function doToCopy()
{
    if(!checkOne("ids")) 
    {
        bizMessage("复制","库存表");
        return false;
    }
    SetValue("Id",getCheckBoxValue("ids"));
    SetAction("toCopyProductStorage");
    frm.submit();
}
*/
key_InitDefault();
key_RegSubmitHandler(doSearch);
</script>
<script type="text/javascript" src = "<%=Config.getWebPath()%>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src = "<%=Config.getWebPath()%>/js/jquery.jstree.js"></script>
<link type="text/css" rel="stylesheet" href="<%=Config.getWebPath()%>/css/themes/default/style.css"/>
<script type="text/javascript">
	   $(function() {
		    $("#warehouseLevel").jstree({
		        "plugins" : [ "themes", "html_data", "checkbox", "ui" ]
		       
		    });
		    
		    var checkedWarehouseCodes = "<%=event.getWarehouseTreeCodes()[0]%>";
		    
		    if(checkedWarehouseCodes == "") checkedWarehouseCodes = "00";
		    
		    var arrayCheckedWarehouseCodes = checkedWarehouseCodes.split(",");
		   
		   		  	
		  	var checkSel = function(ary, val) {
		  		for(var i=0; i<ary.length; i++) {
		  			if(ary[i] == val) {
		  				return true;
		  			}
		  		}
		  		
		  		return false;
		  	}
		    <%if(context.getString("isFirstVisit").equals("false")){ %>
			  	$("#warehouseLevel li").each(
			  		function() 	{
			  			if(checkSel(arrayCheckedWarehouseCodes, $(this).attr("id"))) {
			  				$.jstree._reference("#warehouseLevel").check_node($(this));
			  			} 	  			
			  		}
			  	);
		  	<%}%>
		  
		});
			
</script>

<%=uiBody%>>

<%@ include file="/framework/menu.jsp"%>

<!--********************* Part4:Form  ***************-->
<form id=frm action="<%=Config.getSrv()%>" method="post">
<input type=hidden name="action_code" value="">
<input type=hidden name="Id" value="">
<input type=hidden name=sortOrder value="1">

<!--查询条件保留区域-->
<input type=hidden name="WarehouseCodes" value="<%=event.getWarehouseTreeCodes()[0]%>" > 

<input type=hidden name="s_ProductCode" value="<%=event.getProductCode()%>"> <!--产品编码-->

<input type=hidden name="s_ProductName" value="<%=event.getProductName()%>"> <!--产品名称-->

<input type=hidden name="s_KeyWord" value="<%=event.getKeyWord()%>"> <!--关键字-->

<input type=hidden name="s_ProviderName" value="<%=event.getProviderName()%>"> <!--供应商名称-->

<input type=hidden name="s_IsIncludeZeroStorage" value="<%=event.getIsIncludeZeroStorage()%>"> <!--包含零库存-->

<input type=hidden name="s_IsBuy" value="<%=event.getIsBuy()%>"> <!--是否可采购-->

<input type=hidden name="s_IsNormal" value="<%=event.getIsNormal()%>"> <!--是否正式产品-->

<input type=hidden name="s_DullStorage" value="<%=event.getDullStorage()%>"> <!--呆滞库存-->

<input type=hidden name="s_BalanceMode" value="<%=event.getBalanceMode()%>"> <!--结算模式-->

<input type=hidden name="s_StartLastUpdate" value="<%=event.getStartLastUpdate()%>"> <!--最后修改开始时间-->

<input type=hidden name="s_EndLastUpdate" value="<%=event.getEndLastUpdate()%>"> <!--最后修改结束时间-->

<input type=hidden name=s_KeeperStaffId value="<%=event.getKeeperStaffId()%>"> <!--选择的管理员id-->
<input type=hidden name=s_PositionCode value="<%=event.getPositionCode()%>"> <!--选择的货位code-->

<%@ include file="/framework/list_head.jsp"%>

<br>
<!--********************* Part5:Search Area ***************-->
<%=uiSearchStart%>>
<%
    int key_tab = 1 ;
%>

    <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
            选择仓库：           
            <div id="warehouseLevel" style="background-color: DEE4E9">
				<%=Warehouse.getWarehouseTree(warehouseList,event.getWarehouseCodes())%>
			</div>
        </td>       
    </tr>
    
    <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
            产品编码：&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="text" class="texts" name="i_ProductCode" size="20" value="<%=event.getProductCode()%>" key_tab="<%=key_tab++%>">
            &nbsp;&nbsp;&nbsp;&nbsp;产品名称：&nbsp;&nbsp;
            <input type="text" class="texts" name="i_ProductName" size="20" value="<%=event.getProductName()%>" key_tab="<%=key_tab++%>">
            &nbsp;&nbsp;&nbsp;&nbsp;保管员：&nbsp;&nbsp;
            <%=SelectManager.viewWarehouseStaffSelect(con,loginInfo.getLoginWarehouseCode(),"i_KeeperStaffId",event.getKeeperStaffId(),false,"",SelectManager.SELECT_ALL,"","key_tab="+(key_tab++),event.getWarehouseCodes())%>
        </td>       
    </tr>

    <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
            产品关键字：&nbsp;&nbsp;
            <input type="text" class="texts" name="i_KeyWord" size="20" value="<%=event.viewKeyWord()%>" key_tab="<%=key_tab++%>">
            <% out.print("(对产品编码、名称、型号、规格、品牌、生产厂商、附加属性等七个关键字的模糊查询）");%>
        </td>       
    </tr>

    <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
            供应商名称：&nbsp;&nbsp;
            <input type="text" class="texts" name="i_ProviderName" size="20" value="<%=event.getProviderName()%>" key_tab="<%=key_tab++%>">
            &nbsp;&nbsp;&nbsp;&nbsp;包含零库存：
            <input type="checkbox" class="texts" name="i_IsIncludeZeroStorage" size="20" value="1" <%=event.getIsIncludeZeroStorage().equals("1") ? "checked" : ""%> key_tab="<%=key_tab++%>">
            &nbsp;&nbsp;&nbsp;&nbsp;是否正式产品：
            <%=SelectManager.viewYesOrNoSelect("i_IsNormal",event.getIsNormal(),true,"",SelectManager.SELECT_ALL,"","key_tab="+(key_tab++))%>
        </td>       
    </tr>

    <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
            呆滞库存：&nbsp;&nbsp;&nbsp;&nbsp;
            <%=SelectManager.viewDullStorageSelect("i_DullStorage",event.getDullStorage(),true,"",SelectManager.SELECT_ALL,"","key_tab="+(key_tab++))%>
             &nbsp;&nbsp;&nbsp;&nbsp;是否可采购：
              <%=SelectManager.viewYesOrNoSelect("i_IsBuy",event.getIsBuy(),true,"",SelectManager.SELECT_ALL,"","key_tab="+(key_tab++))%>
            &nbsp;&nbsp;&nbsp;&nbsp;结算模式：&nbsp;&nbsp;
            <%=SelectManager.viewYKorMD("i_BalanceMode",event.getBalanceMode(),true,"",SelectManager.SELECT_ALL,"","key_tab="+(key_tab++))%>
        </td>       
    </tr>

    <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
            最后操作时间：
            <%=framework.custom.UIManager.generateDateInput("i_StartLastUpdate", event.getStartLastUpdate())%> 至 <%=framework.custom.UIManager.generateDateInput("i_EndLastUpdate", event.getEndLastUpdate())%>
              &nbsp;&nbsp;&nbsp;&nbsp;仓库货位：
            <%=SelectManager.viewWarehousePosition(con,loginInfo.getLoginWarehouseCode(),"i_PositionCode",event.getPositionCode(),false,"",SelectManager.SELECT_ALL,"","key_tab="+(key_tab++),event.getWarehouseCodes())%>
 
        </td>       
    </tr>

    <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
            按排序：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    
            <select name="i_OrderField">
                <option value="" <%=(event.getOrderField().equals("1"))?"selected":""%>>设置排序字段</option>
                
                <option value="WAREHOUSE_CODE" <%=(event.getOrderField().equals("WAREHOUSE_CODE"))?"selected":""%>>仓库</option>

                <option value="PRODUCT_CODE" <%=(event.getOrderField().equals("PRODUCT_CODE"))?"selected":""%>>产品编码</option>

                <option value="PRODUCT_MONEY" <%=(event.getOrderField().equals("PRODUCT_MONEY"))?"selected":""%>>金额</option>

                <option value="LAST_UPDATE_TIME" <%=(event.getOrderField().equals("LAST_UPDATE_TIME"))?"selected":""%>>最后操作时间</option>

            </select>
            &nbsp;&nbsp;
            <input type="radio" name="i_OrderDesc" value="false" <%=(event.isOrderDesc()==false)?"checked":""%> >升序
            <input type="radio" name="i_OrderDesc" value="true"  <%=(event.isOrderDesc()==true)?"checked":""%>  >降序
            <input type="button" value="查询" class="buttons" onclick="doSearch();return false;">&nbsp;<input type="button" value="清空" class="buttons" onclick="doClearEvent();return false;">
        </td>
    </tr>

<%=uiSearchEnd%>

<!--列表标题-->
<%=UIManager.addListHeadTitle("库存查询")%>

<!--********************* Part6:List Area ***************-->

<%=uiListStart%>>

<%@ include file="/framework/list_foot.jsp"%>

<%
    int index = 1 ;
%>  
    <%=uiListHeadTR%>>

        <!-- <%=UIManager.addListHeadCheckBox() %> -->
        
        <%=UIManager.addListHead("仓库",index++)%>

        <%=UIManager.addListHead("货位",index++)%>

        <%=UIManager.addListHead("产品编码",index++)%>

        <%=UIManager.addListHead("产品名称",index++,"num")%>

        <%=UIManager.addListHead("单位",index++)%>
        
        <%=UIManager.addListHead("规格",index++)%>

        <%=UIManager.addListHead("型号",index++)%>

        <%=UIManager.addListHead("品牌",index++)%>

        <%=UIManager.addListHead("供应商",index++)%>

        <%=UIManager.addListHead("单价",index++)%>
        <% if(isTel){%>
             <%=UIManager.addListHead("进价",index++)%>
            <% }%>
        <%=UIManager.addListHead("库存数量",index++)%><!--
        
        <%=UIManager.addListHead("申购数量",index++)%>

        --><%=UIManager.addListHead("金额",index++)%>

        <%=UIManager.addListHead("结算模式",index++)%>

        <%=UIManager.addListHead("最后操作时间",index++)%>
        
        <%=UIManager.addListHead("保管员",index++)%>
        
        <%=UIManager.addListHead("最高库存",index++)%>
        
    <%=uiListHeadTREnd%>>
    
    <!--data-->
<%
    double totalMoney = 0;
    for(int i=0;i<list.size();i++)
    {
        WarehouseProductView obj = (WarehouseProductView)list.get(i);
        String warehouseCode1 = obj.getWarehouseCode().substring(0,6);
        String productCode = obj.getProductCode();
        String[] maxCountArr = ProductStorage.getMaxCount(warehouseCode1,productCode);
        float maxCount = 0;
        float productCount = 0;
        String maxCountStr = "";
        if(maxCountArr != null && maxCountArr[0] != null){
        	 maxCount = Float.parseFloat(maxCountArr[0]);
        	 maxCountStr = maxCountArr[0];
        	 String[] productCountArr = ProductStorage.getProductCount(warehouseCode1,productCode);
        	 if(productCountArr !=null && productCountArr[0] != null){
        		 productCount = Float.parseFloat(productCountArr[0]);
        	 }
        }
      
         
        Product pro = Product.fetch(con,obj.getProductId());
        String[] str = ProductStorage.getSimpleProductStorage(obj.getId());
        ProductStorage ps = ProductStorage.fetch(con, obj.getId());
        
        if(ps == null) ps = ProductStorage.fetch();
        
        if (pro==null) pro = new Product();
%>
    <%
    	String uiTr = null;
        if (WarehouseProductView.getDullStorageTimes(obj.getLastUpdateTime()) == 180) {
        	uiTr =uiListDataTR_My[2];
  
        } else if (WarehouseProductView.getDullStorageTimes(obj.getLastUpdateTime()) == 90) {
        	uiTr =uiListDataTR_My[1];
   
        } else if (WarehouseProductView.getDullStorageTimes(obj.getLastUpdateTime()) == 60) {
        	uiTr =uiListDataTR_My[0];
 
        } else {
        	uiTr =uiListDataTR[i%2];
  
        }
  
     if(productCount > maxCount){
    	 uiTr = uiListDataTR_My[3];
   
     }
    %>
    
     <%=uiTr%> align=center>
       <!-- <%=uiListDataTD%>>
            <input type="checkbox" name="ids" value="<%=obj.getId()+"@@"+obj.getWarehouseCode()%>">
        </td>
        -->
        <%=uiListDataTD%>><%=obj.getWarehouseName()%></td>
    
        <%=uiListDataTD%>><%=obj.viewPositionName(con)%></td>
    
        <%=uiListDataTD%>><%=obj.getProductCode()%></td>
    
        <%=uiListDataTD%>><%=pro.getName()%></td>
    
        <%=uiListDataTD%>><%=pro.getProductUnit()%></td>
    
        <%=uiListDataTD%>><%=pro.getSpec()%></td>
    
        <%=uiListDataTD%>><%=pro.getModel()%></td>
    
        <%=uiListDataTD%>><%=pro.getProductBrand()%></td>
    
        <%=uiListDataTD%>><%=ps.viewProviderName(con)%></td>
    
        <%=uiListDataTD%>><%=framework.core.StringUtil.showPrice(str[0]) %></td>
        <%if(isTel){%>
        <%=uiListDataTD%>><%=ps.viewActualPrice(con)%></td>
        <%}%>
        <%=uiListDataTD%>><%=StringUtil.showCount(obj.viewProductCount(con))%></td><!--
        
        <%=uiListDataTD%>><%=StringUtil.showCount(ProductStorage.getOrderCount(con, obj.getWarehouseCode(), obj.getProductCode()) + "")%></td>
    
        --><%=uiListDataTD%>><%=framework.core.StringUtil.showPrice(obj.viewProductMoney(con))%></td>
    
        <%=uiListDataTD%>><%="1".equalsIgnoreCase(obj.viewBalanceMode(con)) ? "压库" : "买断"%></td>
    
        <%=uiListDataTD%>><%=obj.viewLastUpdateTime(con)%></td>
        <%   GSAutoAuditongDateConfigurator.getInstance();
        WarehouseStaff staff =null;
        String warehouseCode = obj.getWarehouseCode().substring(0,obj.getWarehouseCode().length()-2);
        if(GSAutoAuditongDateConfigurator.isShareDatesWarehouses(warehouseCode)){
        	Conditions conditions = new Conditions();
        	conditions.add("product_id",obj.getProductId());
        	if(GSAutoAuditongDateConfigurator.isNoShareWarehouseProductDatesWarehouses(warehouseCode)){
        		conditions.add("warehouse_code",conditions.LIKE,obj.getWarehouseCode()+"%");
        	}else{
        		conditions.add("warehouse_code",conditions.LIKE,warehouseCode+"%");
        	}
        	WarehouseProduct wp =WarehouseProduct.fetch(con,conditions);
        	if(wp==null){
        		staff=null;
        	}else{
        		staff = WarehouseStaff.fetch(con,wp.getKeeperStaffId());
        	}
        } else{
            staff = WarehouseStaff.fetch(con,obj.getKeeperStaffId());
        }
        %>
        <%=uiListDataTD%>><%=staff==null?"":staff.getName()%></td>
        <% totalMoney = totalMoney + Double.parseDouble(obj.viewProductMoney(con)); %>

        </td>
        <%=uiListDataTD%>><%= maxCountStr%></td>
    </tr>
<%  
    }
%>  

<%=uiListDataTR[0]%> align=center>    
<%=uiListDataTD%> colspan='16' align = right >
            <b><%="当前页金额合计:"+StringUtil.showPrice(String.valueOf(totalMoney)) %></b>
    </td>
</tr>
<%=uiListDataTR[0]%> align=center>
<%=uiListDataTD%> colspan='16' align = right >
            <b><%="当前条件总金额:"+StringUtil.showPrice(String.valueOf(allMoney))%></b>
    </td>
</tr>

<%@ include file="/framework/list_foot2.jsp"%>

<%=uiListEnd%>


<!--********************* Part7:Action Area ***************-->
<%=uiCommandStart%>>
    <%=uiCommandTR%>>
      <%=uiCommandTD%>>
   		<span style="width:10px; height:10px; background-color:#FFFF37;"></span> 60---90天
        </td>
        
    <%=uiCommandTD%>>
  <span style="width:10px; height:10px; background-color:#FFA042;"></span>90---180天
        </td>
          
    <%=uiCommandTD%>>
 <span style="width:10px; height:10px; background-color:#FF5809;"></span>180天以上
        </td>
        
    <%=uiCommandTD%> >
		白色表示0---60天
        </td>
        
           <%=uiCommandTD%>>
 <span style="width:10px; height:10px; background-color:#800080;"></span>最高库存
        </td>
    
        <%=uiCommandTD%>>
     
        <!--
        <input type=button value="   添加   " class="buttons" onclick="doToAdd();return false;">
        
        <input type=button value="   复制   " class="buttons" onclick="doToCopy();return false;">
        
        <input type=button value="   修改   " class="buttons" onclick="doToUpdate();return false;">
        <input type=button value="   删除   " class="buttons" onclick="doDelete();return false;">
        -->
       <!--  <input type=button value=" 生成订单 " class="buttons" onclick="createOrder();return false;"> -->
       
        <input type=button value="   导出   " class="buttons" onclick="doExport();return false;">
        </td>
    </tr>   
<%=uiCommandEnd%>
</form>





<%@ include file="/framework/foot.jsp"%>

<!--
    Author    :Wing
    FileName  :/system/base/ProductStorageList.jsp
-->
